import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/common/user_helper.dart';
import 'package:flutter_learn_vi/src/net/dio_utils.dart';
import 'package:flutter_learn_vi/src/utils/navigator_utils.dart';
import 'package:flutter_learn_vi/src/utils/toast_utils.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2020/12/11.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///编辑工作简历
class MinePersonResumAddPage extends StatefulWidget {
  @override
  _MinePersonResumAddPageState createState() => _MinePersonResumAddPageState();
}

class _MinePersonResumAddPageState extends State<MinePersonResumAddPage> {
  TextEditingController _editingController = TextEditingController();

  FocusNode _focusNode = FocusNode();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _editingController.text = UserHelper.getInstance.userBean.userResume;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("编辑工作简历"),
      ),

      ///填充布局
      body: Container(
          color: Colors.white,
          width: double.infinity,
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  padding: EdgeInsets.all(12),
                  child: TextField(
                    controller: _editingController,
                    maxLength: 500,
                    maxLines: 20,
                    focusNode: _focusNode,
                    style: TextStyle(),
                    decoration: InputDecoration(
                        hintText: "请输入您的工作简历(最多500字)",
                        border: OutlineInputBorder()),
                  ),
                ),
                Align(
                  child: Container(
                    width: 100,
                    margin: EdgeInsets.only(right: 12),
                    child: ElevatedButton(
                      onPressed: () {
                        String text = _editingController.text;
                        if (text.length == 0) {
                          ToastUtils.showToast("请输入您的工作简历");
                          return;
                        }
                        alertPersonResumFunction(text);
                      },
                      child: Text("提交"),
                    ),
                  ),
                  alignment: Alignment.centerRight,
                ),
                Container(
                  padding: EdgeInsets.all(12),
                  child: Text(
                    "注意:请发布规范的内容，不可发布局色情、欺诈、广告等内容，新发布的内容管理员审核通过后方可被其他人看到",
                    style: TextStyle(color: Colors.redAccent),
                  ),
                ),
              ],
            ),
          )),
    );
  }

  Future<bool> alertPersonResumFunction(String text) async {
    _focusNode.unfocus();
    Map<String, dynamic> map = {
      "userResume": text,
    };
    ResponseInfo partResponseInfo = await DioUtils.instance.postRequest(
      url: HttpHelper.userInfoResum,
      jsonMap: map,
    );
    if (partResponseInfo.success) {
      LogUtil.e("修改成功");
      UserHelper.getInstance.userBean.userResume = text;
      ToastUtils.showToast("修改成功");
      NavigatorUtils.pop(context, parameters: text);
    } else {
      LogUtil.e("修改成功");
      ToastUtils.showToast("修改失败${partResponseInfo.message}");
    }

    return Future.value(true);
  }
}
